fix cppcheck constVariable warnings (#1070)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Wed, 19 Apr 2023 00:44:22 +0000 (18:44 -0600)
committerGitHub <noreply@github.com>
Wed, 19 Apr 2023 00:44:22 +0000 (18:44 -0600)
* fix cppcheck constVariable warnings.

* guard against qt container detachement.

garmin_fit.cc
gbser_posix.cc
resample.cc
util.cc

index 8edb39584eb45dddd9bb0073f63be35ed6c3b353..0cc111d035b7fcfacd1579b95a29a4fd1e7d55d1 100644 (file)
@@ -1248,7 +1248,7 @@ GarminFitFormat::fit_collect_track_tlr(const route_head* rte)
   fit_write_msg_event(track_date_time, kEventTimer, kEventTypeStart, 0);
 
   // Write track/course points for the whole track
-  for (auto& crpt: course) {
+  for (const auto& crpt: course) {
     if (crpt.is_course_point) {
       fit_write_msg_course_point(crpt.creation_time,
                                  crpt.lat,
index 9cf9904e6c0761bdd5aefef991c69cc61a4ce9aa..1ea54808e99af74912a45c079e4d9faa4223736d 100644 (file)
@@ -186,7 +186,7 @@ int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity,
   gbser_handle* h = gbser_get_handle(handle);
   speed_t s;
 
-  static unsigned bit_flags[] = {
+  static const unsigned bit_flags[] = {
     0, 0, 0, 0, 0, CS5, CS6, CS7, CS8
   };
 
index 2b72ea0f57f956c6b55176d867664bb4fc02e691..251576b6908e2fc4f5b40c43931a587ce57d27db 100644 (file)
@@ -88,8 +88,7 @@ void ResampleFilter::average_waypoint(Waypoint* wpt, bool zero_stuffed)
     }
     counter = 0;
     if (global_opts.debug_level >= 5) {
-      for (auto& entry : history) {
-        auto [pos, avc, alt] = entry;
+      for (const auto& [pos, avc, alt] : qAsConst(history)) {
         qDebug() << "initial conditions" << pos << avc << alt;
       }
       qDebug() << "initial accumulator" << accumulated_position << accumulated_altitude_valid_count << accumulated_altitude;
diff --git a/util.cc b/util.cc
index ca7b2a4a4d1ecebf6c5479fe38a104c645da225f..9510543b70e99a8a90fbf3b3369abdd48aec5781 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -570,7 +570,7 @@ le_write32(void* ptr, const unsigned value)
 time_t
 mkgmtime(struct tm* t)
 {
-  static int      m_to_d[12] =
+  static const int      m_to_d[12] =
   {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
 
   short month = t->tm_mon;